package cn.dida.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.dida.dao.ProductDao;
import cn.dida.model.Pageable;
import cn.dida.model.Product;
import cn.dida.service.ProductService;
/**
 * 产品管理 接口实现类
 * @author weiwei
 *
 */
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductDao productDao;

    @Override
    public Product getProductById(Integer companyId, Integer id) {
        return productDao.getById$Company(id, companyId);
    }

    @Override
    public Product getProductByNumber(Integer companyId, String number) {
        return productDao.getByNum$Company(number, companyId);
    }

    @Override
    public Product getProductByName(Integer companyId, String name) {
        return productDao.getByName$Company(name, companyId);
    }

    @Override
    public Product getProductByBarcode(Integer companyId, String barcode) {
        return productDao.getByBarcode$Company(barcode, companyId);
    }

    @Override
    public Pageable<Product> queryProduct(Integer companyId, String keyword, Integer state, int page) {
        return productDao.query(companyId, keyword, state, page);
    }
    @Transactional
    @Override
    public Boolean insertProduct(Product product) {
        return productDao.insert(product) == 1;
    }
    @Transactional
    @Override
    public Boolean updateProduct(Product product) {
        return productDao.update(product) == 1;
    }
    @Transactional
    @Override
    public Boolean deleteProductByNumber(Integer companyId, String number) {
        return productDao.delete(companyId, number) == 1;
    }

    @Override
    public List<Product> getProductListByIds(String ids) {
        // TODO Auto-generated method stub
        return productDao.getProductListByIds(ids);
    }

    @Override
    public List<Product> getProductsByActivityId(String activityId) {
        // TODO Auto-generated method stub
        return productDao.getProductsByActivityId(activityId);
    }

    @Override
    public List<Product> queryProductForExport(Integer companyId,
                                               String keyword, Integer state) {
        // TODO Auto-generated method stub
        return productDao.queryForExport(companyId, keyword, state);
    }

    /**
     * 根据编码获取产品信息
     * @param number
     * @return
     */
    @Override
    public  List<Product> getByNumber(String number){
        return productDao.getByNumber(number);
    }
}
